import Vue from 'vue';
import Router from 'vue-router';
import { Dialog } from 'vant';

Vue.use(Router);

const routes = [
  {
    path: '*',
    redirect: '/homeClass'
  },
  {
    name: 'homeClass',
    component: () => import('./view/homeClass'),
    meta: {
      title: '客户俱乐部'
    }
  },
  {
    name: 'equity',
    component: () => import('./view/equity'),
    meta: {
      title: '悦享积分'
    }
  },
  {
    name: 'third',
    component: () => import('./view/equity/third'),
    meta: {
      title: ''
    }
  },
  {
    name: 'anotherLink',
    component: () => import('./view/equity/anotherLink'),
    meta: {
      title: '财富资讯'
    }
  },
  {
    name: 'management',
    component: () => import('./view/equity/management'),
    meta: {
      title: '理财'
    }
  },
  {
    name: 'fund',
    component: () => import('./view/equity/fund'),
    meta: {
      title: '基金'
    }
  },
  {
    name: 'insurance',
    component: () => import('./view/equity/insurance'),
    meta: {
      title: '保险'
    }
  },
  {
    name: 'metal',
    component: () => import('./view/equity/metal'),
    meta: {
      title: '贵金属'
    }
  },
  {
    name: 'debt',
    component: () => import('./view/equity/debt'),
    meta: {
      title: '国债'
    }
  },
  {
    name: 'deposit',
    component: () => import('./view/equity/deposit'),
    meta: {
      title: '资金存管'
    }
  },
  {
    name: 'construction',
    component: () => import('./view/equity/construction'),
    meta: {
      title: '页面升级中'
    }
  },
  {
    name: 'etc',
    component: () => import('./view/equity/etc'),
    meta: {
      title: '信用卡活动'
    }
  },
  {
    name: 'tengxun',
    component: () => import('./view/equity/tengxun'),
    meta: {
      title: ''
    }
  },
  {
    name: 'home',
    component: () => import('./view/home'),
    meta: {
      title: '个人中心'
    }
  },
  {
    name: 'real_name',
    component: () => import('./view/real_name'),
    meta: {
      title: '实名认证'
    }
  },
  {
    name: 'personInfo',
    component: () => import('./view/personInfo'),
    meta: {
      title: '个人资料'
    }
  },
  {
    name: 'activity',
    component: () => import('./view/activity'),
    meta: {
      title: '活动中心'
    }
  },
  {
    name: 'actDetail',
    component: () => import('./view/activity/detail'),
    meta: {
      title: '产品详情'
    }
  },
  {
    name: 'success',
    component: () => import('./view/activity/success'),
    meta: {
      title: '秒杀成功'
    }
  },
  {
    name: 'seckill',
    component: () => import('./view/activity/seckill'),
    meta: {
      title: '限时秒杀'
    }
  },
  // 热点资讯
  {
    name: 'hotInfor',
    component: () => import('./view/hotInfor'),
    meta: {
      title: '热点资讯'
    }
  },
  {
    name: 'hotDetail',
    component: () => import('./view/hotInfor/detail'),
    meta: {
      title: '资讯标题'
    }
  },
  {
    name: 'error',
    component: () => import('./view/common/error'),
    meta: {
      title: '页面施工中'
    }
  },
  {
    name: 'update',
    component: () => import('./view/common/update'),
    meta: {
      title: '页面升级中'
    }
  },
  {
    name: 'points-exp',
    component: () => import('./view/activity/points-exp')
  },
  {
    name: 'myOrder',
    component: () => import('./view/myOrder'),
    meta: {
      title: '我的订单'
    }
  },
  {
    name: 'write-off',
    component: () => import('./view/myOrder/write-off'),
    meta: {
      title: '订单核销'
    }
  },
  {
    name: 'search',
    component: () => import('./view/points/search'),
    meta: {
      title: '搜索'
    }
  },
  {
    name: 'searchList',
    component: () => import('./view/points/searchList'),
    meta: {
      title: '搜索'
    }
  },

  {
    name: 'points',
    component: () => import('./view/points/normalList'),
    meta: {
      title: '权益商城'
    },
    children: [
      {
        path: 'detail',
        name: 'detail',
        component: () => import('./view/points/detail'),
        meta: {
          title: '权益商城'
        },
        children: [
          {
            path: 'status',
            name: 'status',
            component: () => import('./view/points/status'),
            meta: {
              title: '确认订单'
            },
            children: [
              {
                path: 'mycoupon',
                name: 'mycoupon',
                component: () => import('./view/mycoupon'),
                meta: {
                  title: '我的权益'
                }
              }
            ]
          },
          {
            path: 'status1',
            name: 'status1',
            component: () => import('./view/points/status1')
          }
        ]
      }
    ]
  },
  {
    name: 'mycoupon',
    component: () => import('./view/mycoupon'),
    meta: {
      title: '我的权益'
    }
  },
  {
    name: 'coinDetail',
    component: () => import('./view/coin/coinDetail'),
    meta: {
      title: '积分明细'
    }
  },
  {
    name: 'error_page',
    component: () => import('./view/errorPage'),
    meta: {
      title: '公告'
    }
  },
  {
    name: 'enterInfo',
    component: () => import('./view/enterInfo'),
    meta: {
      title: '新增白名单'
    }
  },
  {
    name: 'updateUserWhiteList',
    component: () => import('./view/updateUserWhiteList'),
    meta: {
      title: '修改白名单'
    }
  },
  {
    name: 'searchCoin',
    component: () => import('./view/updateUserWhiteList/searchCoin'),
    meta: {
      title: '查询积分'
    }
  },
  {
    name: 'turntableCoin',
    component: () => import('./view/activity/turntableCoin'),
    meta: {
      title: '好礼转不停 积分任你拿'
    }
  },
  {
    name: 'actStation',
    component: () => import('./view/activity/actStation'),
    meta: {
      title: '活动网点'
    }
  },
  {
    name: 'citizenCard',
    component: () => import('./view/activity/citizenCardLine'),
    meta: {
      title: '邮储市民卡一元购'
    }
  },
  {
    name: 'wxcitizenCard',
    component: () => import('./view/activity/citizenCardLine/wxindex'),
    meta: {
      title: '邮储市民卡一元购'
    }
  },
  {
    name: 'getoil',
    component: () => import('./view/activity/citizenCardLine/getoil'),
    meta: {
      title: '邮储市民卡一元购'
    }
  },
  {
    name: 'citizenorder',
    component: () => import('./view/activity/citizenCardLine/myorder'),
    meta: {
      title: '我的订单'
    }
  },
  {
    name: 'wxcitizenorder',
    component: () => import('./view/activity/citizenCardLine/wxmyorder'),
    meta: {
      title: '我的订单'
    }
  },
  {
    name: 'paycenter',
    component: () => import('./view/activity/citizenCardLine/paycenter'),
    meta: {
      title: '充值中心'
    }
  },
  {
    name: 'wxpaycenter',
    component: () => import('./view/activity/citizenCardLine/wxpaycenter'),
    meta: {
      title: '充值中心'
    }
  },
  {
    name: 'tonowpay',
    component: () => import('./view/activity/citizenCardLine/tonowpay'),
    meta: {
      title: '确认订单'
    }
  },
  {
    name: 'wxtonowpay',
    component: () => import('./view/activity/citizenCardLine/wxtonowpay'),
    meta: {
      title: '确认订单'
    }
  },
  {
    name: 'recommend',
    component: () => import('./view/activity/recommend'),
    meta: {
      title: '办理邮储市民卡（社会保障卡）'
    }
  },
  {
    name: 'recommendShare',
    component: () => import('./view/activity/recommend/share'),
    meta: {
      title: '办理邮储市民卡（社会保障卡）'
    }
  },
  {
    name: 'bindCard',
    component: () => import('./view/activity/recommend/bindrecord'),
    meta: {
      title: '邀请办卡记录'
    }
  },
  {
    name: 'ruledetails',
    component: () => import('./view/activity/recommend/ruledetails'),
    meta: {
      title: '市民卡（社会保障卡）详细介绍'
    }
  },
  {
    name: 'cityqrcode',
    component: () => import('./view/activity/recommend/cityqrcode'),
    meta: {
      title: '分享'
    }
  },
  {
    name: 'actstationadress',
    component: () => import('./view/activity/recommend/actstation'),
    meta: {
      title: '活动网点'
    }
  },
  {
    name: 'recommenddetail',
    component: () => import('./view/activity/recommend/actdetail'),
    meta: {
      title: '一元购活动规则'
    }
  },
  {
    name: 'managerComfirm',
    component: () => import('./view/activity/managerComfirm'),
    meta: {
      title: '首页'
    }
  },
  {
    name: 'tocomfirm',
    component: () => import('./view/activity/managerComfirm/tocomfirm'),
    meta: {
      title: '客户活动资格待确认'
    }
  },
  {
    name: 'chinapost',
    component: () => import('./view/activity/managerComfirm/chinapost'),
    meta: {
      title: '中邮证券开户活动'
    }
  },
  {
    name: 'onstation',
    component: () => import('./view/activity/managerComfirm/onstation'),
    meta: {
      title: '邮储市民卡一元购'
    }
  },
  {
    name: 'managerpaycenter',
    component: () => import('./view/activity/managerComfirm/managerpaycenter'),
    meta: {
      title: '充值中心'
    }
  },
  {
    name: 'managerpaynow',
    component: () => import('./view/activity/managerComfirm/managerpaynow'),
    meta: {
      title: '立即支付'
    }
  },
  {
    name: 'paysucce',
    component: () => import('./view/activity/managerComfirm/paysucce'),
    meta: {
      title: '支付成功'
    }
  },
  {
    name: 'paydefult',
    component: () => import('./view/activity/managerComfirm/paydefult'),
    meta: {
      title: '支付失败'
    }
  },
  {
    name: 'dayanwser',
    component: () => import('./view/dayAnswer'),
    meta: {
      title: '每日一答'
    }
  },
  {
    name: 'seckillmodel',
    component: () => import('./view/seckill'),
    meta: {
      title: '限时秒杀'
    }
  },
  {
    name: 'seckilldetail',
    component: () => import('./view/seckill/seckilldetail'),
    meta: {
      title: '产品详情'
    }
  },
  {
    name: 'seckillstatus',
    component: () => import('./view/seckill/seckillstatus'),
    meta: {
      title: '确认订单'
    }
  },
  {
    name: 'haibao',
    component: () => import('./view/seckill/haibao'),
    meta: {
      title: '分享'
    }
  },
  {
    name: 'managershare',
    component: () => import('./view/seckill/yaoqing'),
    meta: {
      title: '我的邀请'
    }
  },
  {
    name: 'seckillsucce',
    component: () => import('./view/seckill/seckillsucce'),
    meta: {
      title: '秒杀成功'
    }
  },
  {
    name: 'managerAd',
    component: () => import('./view/seckill/managershare'),
    meta: {
      title: '邮储美周末--超值秒杀日'
    }
  },
  {
    name: 'seckeillrule',
    component: () => import('./view/seckill/seckeillrule'),
    meta: {
      title: '秒杀规则'
    }
  },
  {
    name: 'stopact',
    component: () => import('./view/seckill/stopact'),
    meta: {
      title: '系统升级公告'
    }
  },
  {
    name: 'citizenrule',
    component: () => import('./view/activity/citizenCardLine/citizenrule'),
    meta: {
      title: '市名卡（社会保障卡）'
    }
  },
  {
    name: 'qrcodeShare',
    component: () => import('./view/qrcodeShare'),
    meta: {
      title: '分享海报'
    }
  },
  // 答题--------------开始
  {
    name: 'dati_home',
    component: () => import('./view/activity/dati/home'),
    meta: {
      title: '答题'
    }
  },
  {
    name: 'dati_goods',
    component: () => import('./view/activity/dati/goods'),
    meta: {
      title: '积分明细'
    }
  }
  // 答题--------------结束
];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});
// console.log(routes);
const router = new Router({ routes });
router.beforeEach((to, from, next) => {
  console.log(document.URL);
  Dialog.close();
  localStorage.setItem('LocalUrl', document.URL);
  const title = to.meta && to.meta.title;
  // console.log(title);
  if (title) {
    document.title = title;
  }
  next();
});

export { router };
